package pl.elka.simulator.core.configurationCommand.impl;

import java.util.List;

import pl.elka.simulator.core.Constraint;
import pl.elka.simulator.core.Position;
import pl.elka.simulator.core.configurationCommand.ConfigurationCommandType;
import pl.elka.simulator.core.configurationCommand.ICommandParam;
import pl.elka.simulator.core.configurationCommand.IConfigurationCommand;
import pl.elka.simulator.core.configurationCommand.ables.IAbleToConfiguration;
import pl.elka.simulator.core.configurationCommand.ables.IAbleToConstraintConfiguration;
import pl.elka.simulator.core.configurationCommand.impl.param.PositionsListCommandParam;

public class AddConstraintConfigurationCommand implements IConfigurationCommand{

	private ICommandParam param;
	@Override
	public IConfigurationCommand newInstance() {		
		return new AddConstraintConfigurationCommand();
	}

	@Override
	public void setParam(ICommandParam param) {
		this.param = param;
	}

	@Override
	public ICommandParam getParam() {
		return param;
	}

	@Override
	public ConfigurationCommandType getType() {
		return ConfigurationCommandType.AddConstraintConfigurationCommand;
	}
	@Override
	public void execute(IAbleToConfiguration able){
		IAbleToConstraintConfiguration ca = (IAbleToConstraintConfiguration) able;
		
		List<Constraint> constraints = ca.getConstraints();
		
		List<Position> poss = ((PositionsListCommandParam)getParam()).getPositions();		
		constraints.add(new Constraint(poss));
		
		ca.setConstraints(constraints);
	}
	
}
